package net.akcegaraz.tipleague.client.view;

import java.util.Collection;
import java.util.HashMap;

import net.akcegaraz.tipleague.client.presenter.RoundPresenter.Display;
import net.akcegaraz.tipleague.shared.domain.Bet;
import net.akcegaraz.tipleague.shared.domain.Ticket;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class RoundView extends Composite implements Display {

    private FlexTable flexTabel = null;

    public RoundView() {
	HorizontalPanel panel = new HorizontalPanel();
	initWidget(panel);
	panel.add(new Label("round"));

	flexTabel = new FlexTable();
	panel.add(flexTabel);
    }

    public Widget asWidget() {
	return this;
    }

    public void viewRound(HashMap<String, Ticket> tickets) {
	Collection<Ticket> values = tickets.values();
	int i = 0;
	int j = 0;
	for (Ticket ticket : values) {
	    flexTabel.setText(i, j++, ticket.getPlayer().getName());
	    for (Bet bet : ticket.getBets()) {
		flexTabel.setText(i, j++, bet.getBet());
	    }
	    j = 0;
	    i++;
	}
    }
}
